﻿<UserControl x:Class="MVVM.Demo.AddEditCustomerView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:MVVM.Demo"
    Height="Auto" Width="Auto" Background="White">
    
    
 
    
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="60"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        
        <Grid Grid.Row="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
              Background="Black">
            
            <Grid.RowDefinitions>
                <RowDefinition Height="*"/>
                <RowDefinition Height="2"/>
            </Grid.RowDefinitions>
            
            <StackPanel Margin="10,0,0,0" Orientation="Horizontal" VerticalAlignment="Stretch">
                <Image Source="../Images/Customers.png" HorizontalAlignment="Left" 
                   VerticalAlignment="Center" Width="36" Height="36"/>


                <Label Content="{Binding DisplayName}" FontWeight="Bold" Foreground="Orange"
                   FontSize="18" HorizontalAlignment="Left" VerticalAlignment="Center"/>


            </StackPanel>

            <Rectangle Grid.Row="1" HorizontalAlignment="Stretch" Height="2" Fill="Black" 
                       VerticalAlignment="Bottom"/>


        </Grid>


        <!-- Name-->
        <GroupBox Grid.Row="1" Background="White"
                  BorderBrush="Black" BorderThickness="2" Margin="40,40,40,10">
            <GroupBox.Header>
                    <Label Content="Customer Details" FontWeight="Bold" 
                        FontSize="14" HorizontalAlignment="Left" VerticalAlignment="Center"/>
            </GroupBox.Header>

            
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>

                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="60"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="1.5*"/>
                </Grid.ColumnDefinitions>

                
                <!-- Customer Orders -->
                <Border CornerRadius="0" Grid.Row="0" Grid.Column="2" 
                        Grid.RowSpan="8" Margin="5" Background="White"
                        BorderBrush="Black" BorderThickness="2">


                    <Border.ContextMenu>
                        <ContextMenu x:Name="menu" Margin="0,0,0,0" Height="Auto" Foreground="White"
                                  ItemContainerStyle="{StaticResource ContextMenuItemStyle}"
                                  ItemsSource="{Binding OrderMenuOptions}"
                                  VerticalAlignment="Top">
                        </ContextMenu>
                    </Border.ContextMenu>


                    <Grid>
                        
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="*"/>
                        </Grid.RowDefinitions>

                        <Grid Grid.Row="0" Background="Black" HorizontalAlignment="Stretch">
                            <Label Content="Customers Orders" Margin="5" 
                               Grid.Row="0" HorizontalAlignment="Left"
                               Foreground="Orange" VerticalAlignment="Center" 
                               VerticalContentAlignment="Center"
                               FontWeight="Bold" FontSize="14" Width="150"/>
                        </Grid>
                        
                                


                        <ListView Margin="0,0,0,3" Grid.Row="2"
                          Visibility="{Binding Path=HasOrders, 
                            Converter={StaticResource BoolToVisibilityConv}, 
                            ConverterParameter='True'}"                                  
                          SelectionMode="Single" 
                          local:SortableListBehaviour.IsGridSortable="True"
                          ItemsSource="{Binding CurrentCustomer.Orders}"
                          ItemContainerStyle="{StaticResource ListViewContainer}"
                          ScrollViewer.VerticalScrollBarVisibility="Auto"
                          ScrollViewer.HorizontalScrollBarVisibility="Visible"     
                          IsSynchronizedWithCurrentItem="True"
                          Background="Transparent" 
                          BorderBrush="Transparent" 
                          Foreground="Black" 
                          Opacity="1" 
                          BorderThickness="2" 
                          HorizontalAlignment="Stretch" 
                          VerticalAlignment="Stretch" 
                          Width="Auto" Height="Auto">
                            <ListView.View>
                                <GridView  
                                ColumnHeaderContainerStyle="{StaticResource GridViewColumnHeaderStyle}">
                                    <GridViewColumn Header="OrderId" Width="100" 
                                        DisplayMemberBinding="{Binding Path=OrderId.DataValue}"/>
                                    <GridViewColumn Header="Quantity" Width="100" 
                                        DisplayMemberBinding="{Binding Path=Quantity.DataValue}"/>
                                    <GridViewColumn Header="ProductId" Width="100" 
                                        DisplayMemberBinding="{Binding Path=ProductId.DataValue}"/>
                                    <GridViewColumn Header="DeliveryDate" Width="200" 
                                        DisplayMemberBinding="{Binding Path=DeliveryDate.DataValue}"/>
                                      </GridView>
                            </ListView.View>

                        </ListView>

                    </Grid>
                    

                </Border>



                <Image Grid.Row="0" Grid.RowSpan="2" Grid.Column="0"
                    Source="../Images/Name.png" HorizontalAlignment="Center" 
                   VerticalAlignment="Center" Width="36" Height="36"/>

                <!-- FirstName-->
                <StackPanel Grid.Row="0" Grid.Column="1" Margin="5"
                        Orientation="Horizontal">
                    <Label Content="First Name" FontWeight="Normal" FontSize="11" Width="150"/>
                    <TextBox FontWeight="Normal" FontSize="11" Width="150" Margin="10,0,0,0"
                        Text="{Binding Path=CurrentCustomer.FirstName.DataValue,
                        UpdateSourceTrigger=LostFocus, ValidatesOnDataErrors=True,
                        ValidatesOnExceptions=True}"
                        Style="{StaticResource ValidatingTextBox}"
                        IsEnabled="{Binding Path=CurrentCustomer.FirstName.IsEditable}"/>
                </StackPanel>

                <!-- LastName-->
                <StackPanel Grid.Row="1" Grid.Column="1" Margin="5"
                    Orientation="Horizontal">
                    <Label Content="Last Name" FontWeight="Normal" FontSize="11" Width="150"/>
                    <TextBox FontWeight="Normal" FontSize="11" Width="150" Margin="10,0,0,0"
                        Text="{Binding Path=CurrentCustomer.LastName.DataValue,
                        UpdateSourceTrigger=LostFocus, ValidatesOnDataErrors=True,
                        ValidatesOnExceptions=True}"
                        Style="{StaticResource ValidatingTextBox}"
                        IsEnabled="{Binding Path=CurrentCustomer.LastName.IsEditable}"/>
                </StackPanel>


                <Image Grid.Row="2" Grid.RowSpan="1" Grid.Column="0"
                    Source="../Images/Email.png" HorizontalAlignment="Center" 
                   VerticalAlignment="Center" Width="36" Height="36"/>

                <!-- Email-->
                <StackPanel Grid.Row="2" Grid.Column="1" Margin="5"
                        Orientation="Horizontal">
                    <Label Content="Email" FontWeight="Normal" FontSize="11" Width="150"/>
                    <TextBox FontWeight="Normal" FontSize="11" Width="150" Margin="10,0,0,0"
                        Text="{Binding Path=CurrentCustomer.Email.DataValue,
                        UpdateSourceTrigger=LostFocus, ValidatesOnDataErrors=True,
                        ValidatesOnExceptions=True}"
                        Style="{StaticResource ValidatingTextBox}"
                        IsEnabled="{Binding Path=CurrentCustomer.Email.IsEditable}"/>
                </StackPanel>


                <Image Grid.Row="3" Grid.RowSpan="2" Grid.Column="0"
                    Source="../Images/Mobile.png" HorizontalAlignment="Center" 
                   VerticalAlignment="Center" Width="36" Height="36"/>

                <!-- HomePhoneNumber-->
                <StackPanel Grid.Row="3" Grid.Column="1" Margin="5"
                        Orientation="Horizontal">
                    <Label Content="Home Phone Number" FontWeight="Normal" FontSize="11" Width="150"/>
                    <TextBox FontWeight="Normal" FontSize="11" Width="150" Margin="10,0,0,0"
                        Text="{Binding Path=CurrentCustomer.HomePhoneNumber.DataValue,
                        UpdateSourceTrigger=LostFocus, ValidatesOnDataErrors=True,
                        ValidatesOnExceptions=True}"
                        Style="{StaticResource ValidatingTextBox}"
                        IsEnabled="{Binding Path=CurrentCustomer.HomePhoneNumber.IsEditable}"/>
                </StackPanel>

                <!-- MobilePhoneNumber-->
                <StackPanel Grid.Row="4" Grid.Column="1" Margin="5"
                    Orientation="Horizontal">
                    <Label Content="Mobile Phone Number" FontWeight="Normal" FontSize="11" Width="150"/>
                    <TextBox FontWeight="Normal" FontSize="11" Width="150" Margin="10,0,0,0"
                        Text="{Binding Path=CurrentCustomer.MobilePhoneNumber.DataValue,
                        UpdateSourceTrigger=LostFocus, ValidatesOnDataErrors=True,
                        ValidatesOnExceptions=True}"
                        Style="{StaticResource ValidatingTextBox}"
                        IsEnabled="{Binding Path=CurrentCustomer.MobilePhoneNumber.IsEditable}"/>
                </StackPanel>


                <Image Grid.Row="5" Grid.RowSpan="3" Grid.Column="0"
                    Source="../Images/House.png" HorizontalAlignment="Center" 
                   VerticalAlignment="Center" Width="36" Height="36"/>

                <!-- Address1-->
                <StackPanel Grid.Row="5" Grid.Column="1" Margin="5"
                        Orientation="Horizontal">
                    <Label Content="Address1" FontWeight="Normal" FontSize="11" Width="150"/>
                    <TextBox FontWeight="Normal" FontSize="11" Width="150" Margin="10,0,0,0"
                        Text="{Binding Path=CurrentCustomer.Address1.DataValue,
                        UpdateSourceTrigger=LostFocus, ValidatesOnDataErrors=True,
                        ValidatesOnExceptions=True}"
                        Style="{StaticResource ValidatingTextBox}"
                        IsEnabled="{Binding Path=CurrentCustomer.Address1.IsEditable}"/>
                </StackPanel>

                <!-- Address2-->
                <StackPanel Grid.Row="6" Grid.Column="1" Margin="5"
                    Orientation="Horizontal">
                    <Label Content="Address2" FontWeight="Normal" FontSize="11" Width="150"/>
                    <TextBox FontWeight="Normal" FontSize="11" Width="150" Margin="10,0,0,0"
                        Text="{Binding Path=CurrentCustomer.Address2.DataValue,
                        UpdateSourceTrigger=LostFocus, ValidatesOnDataErrors=True,
                        ValidatesOnExceptions=True}"
                        Style="{StaticResource ValidatingTextBox}"
                        IsEnabled="{Binding Path=CurrentCustomer.Address2.IsEditable}"/>
                </StackPanel>

                <!-- Address3-->
                <StackPanel Grid.Row="7" Grid.Column="1" Margin="5"
                    Orientation="Horizontal">
                    <Label Content="Address3" FontWeight="Normal" FontSize="11" Width="150"/>
                    <TextBox FontWeight="Normal" FontSize="11" Width="150" Margin="10,0,0,0"
                        Text="{Binding Path=CurrentCustomer.Address3.DataValue,
                        UpdateSourceTrigger=LostFocus, ValidatesOnDataErrors=True,
                        ValidatesOnExceptions=True}"
                        Style="{StaticResource ValidatingTextBox}"
                        IsEnabled="{Binding Path=CurrentCustomer.Address3.IsEditable}"/>
                </StackPanel>


            </Grid>
            
            


        </GroupBox>



        <StackPanel Grid.Row="2" Orientation="Horizontal" VerticalAlignment="Top"
                    Margin="40,0,0,0">
            <Button Template="{StaticResource GlassButton}"
	            Content="Save" HorizontalAlignment="Center"
			    VerticalAlignment="Center" Margin="0,0,0,0"
			    Width="90" Height="30"
                Command="{Binding SaveCustomerCommand}"/>
            <Button Template="{StaticResource GlassButton}"
	            Content="Edit" HorizontalAlignment="Center"
			    VerticalAlignment="Center" Margin="10,0,0,0"
			    Width="90" Height="30"
                Command="{Binding EditCustomerCommand}"/>
            <Button Template="{StaticResource GlassButton}"
	            Content="Cancel" HorizontalAlignment="Center"
			    VerticalAlignment="Center" Margin="10,0,0,0"
			    Width="90" Height="30"
                Command="{Binding CancelCustomerCommand}"/>

        </StackPanel>

    </Grid>
    

</UserControl>
